import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt

root = ET.parse("D:\\StarCraft\\bwapi-data\\logs\\g.xml").getroot()
generations = root.findall("generation")

avg_obj = [[],[],[],[]]

for gen in generations:
	for o in avg_obj: o.append(0)
	for g in gen.findall("genome"):
		i = 0
		for o in g.findall("objective"):
			avg_obj[i][len(avg_obj[i])-1] += float(o.get("fitness"))
			i += 1
	for o in avg_obj:
		o[len(o)-1] = o[len(o)-1] / float(len(gen.findall("genome")))
		
plt.subplot(221)
plt.title("$fitness_{FF}$")
plt.xlabel("generations")
plt.ylabel("fitness")
plt.plot(avg_obj[0])
plt.axis([0,len(avg_obj[0])-1,0.885,0.925])
plt.subplot(222)
plt.xlabel("generations")
plt.ylabel("fitness")
plt.title("$fitness_{HP}$")
plt.plot(avg_obj[1])
plt.axis([0,len(avg_obj[0])-1,-0.34,-0.2])
plt.subplot(223)
plt.title("$fitness_{MA}$")
plt.plot(avg_obj[2])
plt.axis([0,len(avg_obj[0])-1,0.41,0.46])
plt.subplot(224)
plt.title("$fitness_{KS}$")
plt.plot(avg_obj[3])
plt.axis([0,len(avg_obj[0])-1,0.2,0.4])
plt.show()

